package com.wn.pianTai.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wn.dal.entity.Book;
import com.wn.serviceLa.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wnlqy
 * @since 2023-04-26 12:10:21
 */
@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookService bookService;

    @RequestMapping("/query")
    public List<Book> query(Integer N){
        return bookService.topN(N);
    }

    @RequestMapping("/detail")
    public Book detail(Long bookId){
        //获取图书详情,并增加阅读量
        Book conmBook = bookService.getById(bookId);
        conmBook.setReadcount(conmBook.getReadcount()+1);

        //修改数据库中书籍的阅读量
        Book book = new Book();
        book.setId(bookId);
        book.setReadcount(conmBook.getReadcount());
        bookService.updateById(book);

        return conmBook;
    }

//    @RequestMapping("pageType")
//    public Page<Book> typeId(Long current, Long size, Integer typeId){
//        return bookService.pageOftype(current,size,typeId);
//    }
    @RequestMapping("pageType")
    public Page<Book> typeId(Long current, Long size, Integer typeId){
        QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("typeId",typeId);
        Page<Book> page = new Page<>(current,size);
        Page<Book> pageResult = bookService.page(page, queryWrapper);
        return pageResult;
    }


}

